#!/usr/bin/perl

###########################################
#Author :  DebugProject _Brebion
#Created : 02/03/07
#Modified : 05/03/07
#Script : Scipt to lanch the debuggeur
###########################################

#Verification de la ligne de commande
if((scalar(@ARGV) !=3)){die "[usage :<root of the directories to deploy> <where to deploy the files> <fileOfTheStation>] "}

$rootOfTheDirectories = $ARGV[0];
$whereToDeploy = $ARGV[1];
$fileOfTheStation= $ARGV[2];

#vérification que le fichier d'entree existe bien
if(!(-e $fileOfTheStation)){die "[The file input doesn't exist]"}


#Ouverture des handles
open(INPUT,"<$fileOfTheStation") || die "[Open file $fileConfig impossible]";

#creation table of stations
@tabStation;

while($ligne=<INPUT>){
	$ligne =~ /(.*);/;
	$tabStation[$#tabStation + 1] = $1;
}

$nbElement=scalar(@tabStation);

for($i=1;$i<=$nbElement;$i++){
	$dir = $rootOfTheDirectories."/host".$i;
	#create the directory if not exists
	$mkdir = `ssh @tabStation[$i-1] "mkdir -p $whereToDeploy"`; 
	$hote = `scp -r $dir @tabStation[$i-1]:$whereToDeploy`;
}

close INPUT

